package com.yupi.springbootinit.controller;

import com.yupi.springbootinit.common.QueryListWhenId;
import com.yupi.springbootinit.common.Result;
import com.yupi.springbootinit.model.entity.ConurseTopicContent;
import com.yupi.springbootinit.model.vo.ConurseTopicContentReponseBody;
import com.yupi.springbootinit.model.vo.ConurseTopicReponseBody;
import com.yupi.springbootinit.service.ConurseTopicService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@CrossOrigin
public class ConurseTopicController {

    @Autowired
    private ConurseTopicService topicService;


    /**
     * 获取指定分类的题目列表
     * @param queryListWhenId 只有一个ID
     * @return 题目列表的集合
     */
    @PostMapping("/topicList")
    public Result<List<ConurseTopicReponseBody>> ConurseTopicReponseBodyList(@Valid  @RequestBody QueryListWhenId queryListWhenId) {
        return Result.success(topicService.queryConurseTopicReponseBodyList(queryListWhenId));
    }

    /**
     * 获取题目的标题以及答案
     * @param queryListWhenId id
     * @return 题目以及答案
     */
    @SneakyThrows
    @PostMapping("/caList")
    public Result<List<ConurseTopicContentReponseBody>> TopicContentAndAnswerList(@Valid @RequestBody QueryListWhenId queryListWhenId) {
        return Result.success(topicService.queryTopicContentAndAnswerList(queryListWhenId.getId()));
    }

}
